<?php

class AbstractMappingConfig{

    protected $parent;
    protected $acceptableMethods = array();
    protected $requiredParams = array();
    protected $configObj;

    protected function includeFile($fileLocation){
        if (file_exists($fileLocation)){
            include($fileLocation);
            return true;
        }else{
            throw new Exception('Couldn\'t find the file');
        }
    }

    public function setParentInterpreter(/*RequestInterpreter*/ $interpreter){
        if ($interpreter instanceof RequestInterpreter){
            $this->parent = $interpreter;
        }else{
            throw new Exception('Invalid Interpreter');
        }
    }

    public function withParam(){
        $argv = func_get_args();
        foreach ($argv as $arg){
            if (!is_array($arg)){
                $this->requiredParams[$arg] = null;
            }else{
                foreach ($arg as $key => $val){
                    $this->requiredParams[$key] = $val;
                }
            }
        }
        return $this;
    }

    protected function abstractCheckMapping(){
        if (count($this->requiredParams) > 0){
            foreach ($this->requiredParams as $key => $val){
                if (!array_key_exists($key,$_REQUEST) || !($val === null || $_REQUEST[$key] == $val)){
                    return false;
                }
            }
        }
        if (count($this->acceptableMethods) == 0 || in_array($_SERVER['REQUEST_METHOD'],$this->acceptableMethods)){
            return true;
        }else{
            throw new Http405Exception('Specified Method has not been found.');
        }
    }

    public static function getXsdPart(){
        return '
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="from" type="xs:string" minOccurs="1" maxOccurs="1"/>
                            <xs:element name="to" type="xs:string" minOccurs="1" maxOccurs="1"/>
                        </xs:sequence>
                    </xs:complexType>
                    ';
    }

    public static function interpretXmlConfig(/*XMLNodeList?*/ $xmlNodes, /*RequestInterpreter*/ $interpreter){
        throw new Exception('Cannot interpret XML without a specific override of interpretXmlConfig.');
    }

    public function setInnerConfigObj(/*StandardInnerConfig*/ $configObj){
        $this->configObj = $configObj;
    }
}
?>